package com.ruoyi.reservations.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.reservations.domain.Reservations;
import com.ruoyi.reservations.service.IReservationsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图书预约Controller
 * 
 * @author anyunyi
 * @date 2025-05-28
 */
@RestController
@RequestMapping("/reservations/dept")
public class ReservationsController extends BaseController
{
    @Autowired
    private IReservationsService reservationsService;

    /**
     * 查询图书预约列表
     */
    @PreAuthorize("@ss.hasPermi('reservations:dept:list')")
    @GetMapping("/list")
    public TableDataInfo list(Reservations reservations)
    {
        startPage();
        List<Reservations> list = reservationsService.selectReservationsList(reservations);
        return getDataTable(list);
    }

    /**
     * 导出图书预约列表
     */
    @PreAuthorize("@ss.hasPermi('reservations:dept:export')")
    @Log(title = "图书预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reservations reservations)
    {
        List<Reservations> list = reservationsService.selectReservationsList(reservations);
        ExcelUtil<Reservations> util = new ExcelUtil<Reservations>(Reservations.class);
        util.exportExcel(response, list, "图书预约数据");
    }

    /**
     * 获取图书预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('reservations:dept:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(reservationsService.selectReservationsById(id));
    }

    /**
     * 新增图书预约
     */
    @PreAuthorize("@ss.hasPermi('reservations:dept:add')")
    @Log(title = "图书预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Reservations reservations)
    {
        return toAjax(reservationsService.insertReservations(reservations));
    }

    /**
     * 修改图书预约
     */
    @PreAuthorize("@ss.hasPermi('reservations:dept:edit')")
    @Log(title = "图书预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reservations reservations)
    {
        return toAjax(reservationsService.updateReservations(reservations));
    }

    /**
     * 删除图书预约
     */
    @PreAuthorize("@ss.hasPermi('reservations:dept:remove')")
    @Log(title = "图书预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reservationsService.deleteReservationsByIds(ids));
    }
}
